package com.gxa.service.impl;

import com.gxa.common.Result;
import com.gxa.mapper.EmpMapper;
import com.gxa.pojo.Emp;
import com.gxa.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
public class EmpServiceImpl implements EmpService {
    @Autowired(required = false)
    private EmpMapper empMapper;
    Result<Object> r = new Result<Object>();

    @Transactional(rollbackFor = Throwable.class)
    @Override
    public Result<Object> addEmp(Emp emp) {


            int result = empMapper.addEmp(emp);
            if (result > 0){
                r.setCode(200);
                r.setMsg("success");
            }
        return r;
    }

    @Override
    public Result<Object> deleteEmp(Integer empno) {
        int result = empMapper.deleteEmp(empno);
        if (result > 0){
            r.setCode(200);
            r.setMsg("success");
        }
        return r;
    }

    @Override
    public Result<Object> updateEmp(Emp emp) {
        int result = empMapper.updateEmp(emp);
        if (result> 0){
            r.setCode(200);
            r.setMsg("success");
        }
        return r;
    }

    @Override
    public Result<Object> selectEmp(Integer empno) {
        List<Emp> result = empMapper.selectEmp(empno);
        if (result!=null){
            r.setCode(200);
            r.setMsg("success");
            r.setData(result);
        }
        return r;
    }
}
